<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品图片列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="common-image-form">
                <input name="modelType" type="hidden" th:value="${modelType}">
                <input name="modelId" type="hidden" th:value="${modelId}">
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="closeItem()">
                <i class="fa fa-reply-all"></i> 关闭
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    const showStatusDict = [[${@dict.getType('show_status')}]];
    const prefix = ctx + "back/commonImage"
    const modelType = $('input[name="modelType"]').val();
    const modelId = $('input[name="modelId"]').val();

    /* 改变状态 */
    function changeStatus(id, isEnable) {
        isEnable = Math.abs(parseInt(isEnable) - 1);
        $.operate.post(prefix + "/edit", {id: id, isEnable: isEnable}, function () {
            $.table.refresh();
        })
    }

    $(function () {
        var options = {
            url: prefix + "/searchList",
            createUrl: prefix + "/add/" + modelType + "/" + modelId,
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            sortName: "orderNum",
            sortOrder: "asc",
            modalName: "图片",
            showColumns: false,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID'
                },
                {
                    field: 'coverUrl',
                    title: '图片',
                    formatter: function (value, row, index) {
                        // var thumbUrl = value + '?imageView2/1/w/64/h/64';
                        return $.common.sprintf("<img class='img-circle img-sm' data-height='%s' data-width='%s' data-target='%s'  style='border-radius: 0;' src='%s' data-src='%s'/>", 400, 'auto', 'self', value, value);
                    }
                },
                {
                    field: 'orderNum',
                    title: '排序',
                },
                {
                    field: 'isEnable',
                    title: '状态',
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(showStatusDict, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if ("0" == row.isEnable) {
                            actions.push('<a class="btn btn-primary btn-xs" href="#" onclick="changeStatus(\'' + row.id + '\',\'' + row.isEnable + '\')"><i class="fa fa-check">启用</i></a>');
                        }
                        if ("1" == row.isEnable) {
                            actions.push('<a class="btn btn-warning btn-xs" href="#" onclick="changeStatus(\'' + row.id + '\',\'' + row.isEnable + '\')"><i class="fa fa-ban">禁用</i></a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>